#pragma once
#include "DXAMLCommon.h"

template <typename T>
class CXcpList
{
public:

	class XCPListNode
	{
	public:
		T * m_pData;
		XCPListNode * m_pNext;
	};


	HRESULT Add(T *pData)
	{
		XCPListNode *pTemp = this->m_pHead;
		HRESULT hr = S_OK;
		XCPListNode *pTempNode = new XCPListNode();
		if ( pTempNode )
		{
			this->m_pHead = pTempNode;
			this->m_pHead->m_pNext = pTemp;
			this->m_pHead->m_pData = pData;
		}
		else
		{
			hr = 0x8007000Eu;
		}
		return hr;
	}

	HRESULT Clean(char bDoDelete)
	{
		XCPListNode *pTemp;
		for (; this->m_pHead; this->m_pHead = pTemp )
		{
			pTemp = this->m_pHead->m_pNext;
			if ( bDoDelete )
				this->DeleteItem(this->m_pHead->m_pData);
			this->m_pHead->m_pData = NULL;
			delete this->m_pHead;
			this->m_pHead = NULL;
		}
		this->m_pHead = NULL;
		return S_OK;
	}

	void DeleteItem(T *pData)
	{
		if(pData)
			delete pData;
	}

	XCPListNode * GetHead()
	{
		return this->m_pHead;
	}
private:
	XCPListNode * m_pHead;
};